clear all

*set working directory
use "Study 3 data.dta"

*political knowledge
recode jk2 2/4=0
recode pk2 1/2=0 3=1 4=0
recode pk3 2=0
recode pk4 1/2=0 3=1 4=0
alpha pk2 pk3 pk4 jk2, item asis gen(Know4) casewise

*combining trait categories
gen dCFprop=dcareprop+dfairprop
gen rCFprop=rcareprop+rfairprop
gen dLAprop=dloyaprop+dauthprop
gen rLAprop=rloyaprop+rauthprop

*ownership
forval x=1/6 {
gen diffhandle`x'=rephandling_`x'-demhandling_`x'
}

gen careprop1=dcareprop if traitdenviro!=""
gen fairprop1=dfairprop if traitdenviro!=""
gen loyaprop1=dloyaprop if traitdenviro!=""
gen authprop1=dauthprop if traitdenviro!=""
gen compprop1=dcompprop if traitdenviro!=""

gen careprop2=dcareprop if traitdpoverty!=""
gen fairprop2=dfairprop if traitdpoverty!=""
gen loyaprop2=dloyaprop if traitdpoverty!=""
gen authprop2=dauthprop if traitdpoverty!=""
gen compprop2=dcompprop if traitdpoverty!=""

gen careprop3=dcareprop if traitdhealth!=""
gen fairprop3=dfairprop if traitdhealth!=""
gen loyaprop3=dloyaprop if traitdhealth!=""
gen authprop3=dauthprop if traitdhealth!=""
gen compprop3=dcompprop if traitdhealth!=""

gen careprop4=rcareprop if traitrsecurity!=""
gen fairprop4=rfairprop if traitrsecurity!=""
gen loyaprop4=rloyaprop if traitrsecurity!=""
gen authprop4=rauthprop if traitrsecurity!=""
gen compprop4=rcompprop if traitrsecurity!=""

gen careprop5=rcareprop if traitrterror!=""
gen fairprop5=rfairprop if traitrterror!=""
gen loyaprop5=rloyaprop if traitrterror!=""
gen authprop5=rauthprop if traitrterror!=""
gen compprop5=rcompprop if traitrterror!=""

gen careprop6=rcareprop if traitrcrime!=""
gen fairprop6=rfairprop if traitrcrime!=""
gen loyaprop6=rloyaprop if traitrcrime!=""
gen authprop6=rauthprop if traitrcrime!=""
gen compprop6=rcompprop if traitrcrime!=""

*partisanship
gen PID=pid
recode PID 1=2 2=6 3/4=4
recode PID 2=1 if pidd==1
recode PID 6=7 if pidr==1
recode PID 4=3 if pidi==1
recode PID 4=5 if pidi==2


************
* analysis *
************

*trait listing proportions by issue type
ttest rcareprop=dcareprop
ttest rfairprop=dfairprop
ttest rloyaprop=dloyaprop
ttest rauthprop=dauthprop
ttest rcompprop=dcompprop


*figure 3
gen x=.
replace x=5 in 1
replace x=4 in 2
replace x=3 in 3
replace x=2 in 4
replace x=1 in 5

gen te=.
gen thi=.
gen tlo=.

ttest rcareprop=dcareprop
replace te=r(mu_1) - r(mu_2) in 1
replace thi=(r(mu_1) - r(mu_2)) + 1.96*r(se) in 1
replace tlo=(r(mu_1) - r(mu_2)) - 1.96*r(se) in 1

ttest rfairprop=dfairprop
replace te=r(mu_1) - r(mu_2) in 2
replace thi=(r(mu_1) - r(mu_2)) + 1.96*r(se) in 2
replace tlo=(r(mu_1) - r(mu_2)) - 1.96*r(se) in 2

ttest rloyaprop=dloyaprop
replace te=r(mu_1) - r(mu_2) in 3
replace thi=(r(mu_1) - r(mu_2)) + 1.96*r(se) in 3
replace tlo=(r(mu_1) - r(mu_2)) - 1.96*r(se) in 3

ttest rauthprop=dauthprop
replace te=r(mu_1) - r(mu_2) in 4
replace thi=(r(mu_1) - r(mu_2)) + 1.96*r(se) in 4
replace tlo=(r(mu_1) - r(mu_2)) - 1.96*r(se) in 4

ttest rcompprop=dcompprop
replace te=r(mu_1) - r(mu_2) in 5
replace thi=(r(mu_1) - r(mu_2)) + 1.96*r(se) in 5
replace tlo=(r(mu_1) - r(mu_2)) - 1.96*r(se) in 5

twoway (scatter x te, msize(medium) msym(0) mcol(gs10)) (rcap tlo thi x, lwidth(medthick) lcol(gs10) horiz xline(0) legend(off) ///
	xtitle("Difference in proportions (R - D)") ysc(range(.5 5.5)) ytitle("") ///
	ylab(5 "Care" 4 "Fairness" 3 "Loyalty" 2 "Authority" 1 "Competence") xlab(-.3(.2).3) ///
	subtitle("Trait Importance (Open)") saving(traitown_open.gph, replace))

	
*trait proportions by issue type among low knowledge
ttest rcareprop=dcareprop if Know4<=.5
ttest rfairprop=dfairprop if Know4<=.5
ttest rauthprop=dauthprop if Know4<=.5
ttest rloyaprop=dloyaprop if Know4<=.5
ttest rcompprop=dcompprop if Know4<=.5




*************
* reshaping *
*************

gen ID=_n

keep diffhandle* careprop1-compprop6 Know4 ID
reshape long diffhandle careprop fairprop loyaprop authprop compprop, i(ID) j(issue)

xtset ID

gen CFprop=(careprop+fairprop)/2
gen LAprop=(loyaprop+authprop)/2

*ownership tests
xtreg diffhandle careprop fairprop loyaprop authprop compprop i.issue, fe vce(cluster ID)
est store trait6
xtreg diffhandle CFprop LAprop compprop i.issue, fe vce(cluster ID)
est store trait3

coefplot trait3, ciopts(lwidth(medthick) lcol(black)) msize(medium) msym(0) mcol(black) keep(CFprop LAprop compprop) xline(0) xlab(-2(1)2) ///
	rename(CFprop="Care & Fairness" LAprop="Loyalty & Authority" compprop="Competence") ///
	xtitle("Effect on Relative Party Handling (R - D)", size(small)) subtitle("Trait Importance (Open)") saving(traiteffects_s3_3.gph, replace)
coefplot trait6, ciopts(lwidth(medthick) lcol(black)) msize(medium) msym(0) mcol(black) keep(careprop fairprop loyaprop authprop compprop) xline(0) xlab(-2(1)2) ///
	rename(careprop="Care" fairprop="Fairness" loyaprop="Loyalty" authprop="Authority" compprop="Competence") ///
	xtitle("Effect on Relative Party Handling (R - D)", size(small)) subtitle("Trait Importance (Open)") saving(traiteffects_s3_6.gph, replace)
graph combine foundationeffects.gph traiteffects.gph traiteffects_s3_3.gph traiteffects_s3_6.gph, ///
	subtitle("Figure 4. Moral Concerns on an Issue Predict Perceived Party Competence") ///
	note("Note: the top left panel plots coefficients for moral relevance on relative party handling (R - D) of an issue. The remaining three panels plot the coefficients" "for trait importance on relative party handling of an issue.", size(vsmall))

*knowledge - subsetted
xtreg diffhandle CFprop LAprop compprop i.issue if Know4<=.5, fe vce(cluster ID) /* bottom 26% */
est store pklo

*knowledge - interactive
xtreg diffhandle c.CFprop##c.Know4 c.LAprop##c.Know4 compprop i.issue, re vce(cluster ID)
est store inter

esttab trait6 trait3 pklo inter using study3.rtf, se r2 obslast nonumber title({\b Table A2. Testing for Moderating Effects of Political Knowledge in Study 1}) ///
 coeflabel(careprop "Compassion" fairprop "Fairness" loyaprop "Loyalty" authprop "Authority" compprop "Competence" CFprop "Compassion & Fairness" ///
 LAprop "Loyalty & Authority" Know4 "Political Knowledge" c.LAprop#c.Know4 "Loyalty & Authority x Knowledge" c.CFprop#c.Know4 "Compassion & Fairness x Knowledge" _cons "Constant") ///
 b(%9.3f) se(%9.3f) r(%9.2f) varwidth(40) replace drop(1.issue 2.issue 3.issue 4.issue 5.issue 6.issue) order(careprop fairprop loyaprop authprop CFprop LAprop compprop Know4 c.CFprop#c.Know4 c.LAprop#c.Know4)

